<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript" src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <title>Boost 搜索引擎</title>
    <style>
        /*去掉内外边距*/
        * {
            margin: 0;
            /*外边距*/
            padding: 0;
            /*内边距*/
        }

        body {
            height: 100%;
        }

        .container {
            width: 800px;
            margin: 0px auto;
            margin-top: 15px;
        }

        .container .search {
            width: 100%;
            height: 50px;
        }

        .container .search input {
            float: left;
            width: 600px;
            height: 50px;
            border: 1px solid black;
            border-right: none;
            padding-left: 10px;
            color: #c1c1c1;


        }

        .container .search button {
            float: left;
            width: 120px;
            height: 52px;
            background-color: #0c70f2;
            color: white;
            font-size: 17px;
            font-family: Georgia, 'Times New Roman', Times, serif;
        }

        .container .result {
            width: 100%;

        }

        .container .result .item {
            padding-top: 20px;

        }

        .container .result .item a {
            text-decoration: none;
            font-size: 20px;
            color: #0c70f2;
        }

        /*设置当鼠标移到上面的时间且保持住*/
        .container .result .item a:hover {
            text-decoration: underline;
        }

        .container .result .item p {
            display: block;
            /*设为快级元素单独占一行使其正常显示*/
            font-size: 14px;
            font-family: Arial, Helvetica, sans-serif;
        }

        .container .result .item i {
            display: block;
            /*设为快级元素单独占一行使其正常显示*/
            font-style: normal;
            color: green;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="search">
            <input type="text" value="请输入关键字">
            <button onclick="Search()">搜索一下</button>
        </div>
        <div class="result">
            <div class="item">
                <a href="#">这是标签</a>
                <p>这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要</p>
                <i>https://www.boost.org/</i>
            </div>
            <div class="item">
                <a href="#">这是标签</a>
                <p>这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要这是摘要</p>
                <i>https://www.boost.org/</i>
            </div>

        </div>
    </div>
    <script>
        function Search() {
            /*alert("hello js");*/
            let query = $(" .container .search input").val();
            console.log("query=" + query);
            $.ajax({
                type: "Get",
                url: "/s?word=" + query,
                success: function (date) {
                    BuildHtml(date);
                }
            });
        }

        function BuildHtml(date) {
            console.log(date);
            let result_lable = $(".container .result");
            result_lable.empty();
            for (let elem of date) {
                /*console.log(elem.title);
                console.log(elem.url);*/
                let a_lable = $("<a>", {
                    text: elem.title,
                    href: elem.url,
                    /*跳转到不同的页面*/
                    target: "_bank"

                });

                let p_lable = $("<p>", {
                    text: elem.dec
                });

                let i_lable = $("<i>", {
                    text: elem.url
                });

                let div_lable = $("<div>", {
                    class: "item"
                });

                a_lable.appendTo(div_lable);
                p_lable.appendTo(div_lable);
                i_lable.appendTo(div_lable);
                div_lable.appendTo(result_lable);

            }
        }
    </script>
</body>

</html>